<template>
  <div>
    <el-row>
      <el-col :span="4">
          <div id="bigDiv">
              <div class="memberDiv" @dblclick="queryInfo(item.id,item.name)" v-for="(item,index) in memberInfo" :key="index">
                {{item.name}}
              </div>
          </div>
      </el-col>
      <el-col :span="20">
        <div class="chatDiv">
                <div id="infoDiv hhDiv">
                  <el-container>
                    <!--头部-->
                    <el-header>
                      <div id="headDiv">
                        <span>{{chat.name}}</span>
                      </div>
                    </el-header>
                    <el-main id="msgDiv">
                      <div style="padding-left:0px">
                        <el-row v-for="item in messageInfo" :key="item">
                          <!--患对医-->
                          <div  v-show="item.direction==0" >
                              <el-col span=2>
                                <el-avatar :size="35" :src="require('../../icons/imgs/unknowuser.png')"></el-avatar>
                              </el-col>
                              <el-col span=22 style="text-align:left">
                                <div class="fontDiv">
                                  <p>{{item.info}}</p>
                                </div>
                              </el-col>
                          </div>
                        <!--医对患-->
                          <div  v-show="item.direction==1" >
                              <el-col span=22 style="text-align:left">
                                <div style="background-color:rgb(142, 255, 127);border-radius: 4px;border: 1px solid white">
                                  <p>{{item.info}}</p>
                                </div>
                              </el-col>
                              <el-col span=2>
                                <!--<el-avatar :size="35" :src="require('../../img'+$store.state.doctor.tDoctorInfo.headImg)"></el-avatar>-->
                              </el-col>
                          </div>

                        </el-row>

                      </div>
                    </el-main>
                  </el-container>


                </div>
                <div id="sendDiv">
                     <el-input type="textarea" rows="8" v-model="chat.info" >

                     </el-input>
                     <el-button type="success" id="sendBtn" @click="sendMsg()" v-show="chat.memberId!=0">发送</el-button>
                </div>
            </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import axios from 'axios'
import { listChatInfo,queryChatInfoByMemberId,saveChatInfo  } from '@/api/xsf/healthyInformation'

export default {
  data() {
    return {
      chatInfo:[],
      memberInfo:[],
      messageInfo:[],
      chat:{
          info:'',
          name:'',
          memberId:0,
      }
    }
  },
  methods:{
    queryInfo(id,name){
        //alert(id);
        this.chat.name=name;
        this.chat.memberId=id;
        queryChatInfoByMemberId(id).then((response)=>{
          this.messageInfo=response.data;
        })
    },
    sendMsg(){
      saveChatInfo(this.chat).then(()=>{
        this.queryInfo(this.chat.memberId,this.chat.name);
        this.chat.info='';
      })
    }
  },
  mounted(){
    listChatInfo().then((response)=>{
        this.chatInfo=response.data;
        for(var i=0;this.chatInfo.length;i++){
          var b=false;
          for(var j=0;j<this.memberInfo.length;j++){
              if(this.memberInfo[j].id==this.chatInfo[i].memberId){
                  b=true
              }
          }
          if(b==false){
              this.memberInfo.push(this.chatInfo[i].tMember);
          }
        }
    })
  }
}
</script>

<style>
  .memberDiv{
    height: 60px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
    text-align: center;
    color: darkblue;
    padding-top: 18px;
    font-size: 20px;
  }
  #bigDiv{
    background-color:azure;
    height: 900px;
  }
.hhDiv ,#headDiv{
        box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
}
#headDiv{
  height: 60px;
  font-size: 40px;
  text-align: center;
    background-color:azure;

}
#questDiv{
  /*width: 1000px;*/
  text-align: left;
  padding-left: 0px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)

}
.chatDiv{
  height: 447px;
}
#infoDiv{
  height: 320px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
}
#sendBtn{
  position: relative;
  right: -1150px;
  bottom: 40px;
}
#msgDiv{
  /*overflow:scroll;*/
  height: 450px;
}
.fontDiv{
  background-color: azure;
  border-radius: 4px;
  border: 1px solid white;

}




</style>
